package de.wbh.gwt.form.layouter.gwt.ui.view.widget;

import com.google.common.collect.ImmutableSet;
import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.user.client.ui.CustomButton;

import de.wbh.gwt.form.layouter.gwt.ui.view.widget.Button.Resources.Style;

public class Button extends CustomButton {

	public static interface Resources extends ClientBundle {
		static interface Style extends CssResource {
			String button();
		}

		@Source("button.css")
		Style style();
	}

	private final ImmutableSet<Face> faces = ImmutableSet.of(getUpFace(), getUpHoveringFace(), getUpDisabledFace(), getDownFace(), getDownHoveringFace(), getDownDisabledFace());

	private final Style style;

	public Button() {
		this(GWT.<Resources> create(Resources.class));
	}

	public Button(Resources resources) {
		this.style = resources.style();
		this.style.ensureInjected();

		addStyleName(this.style.button());
	}

	@Override
	protected void onClick() {
		setDown(false);
		super.onClick();
	}

	@Override
	protected void onClickCancel() {
		setDown(false);
	}

	@Override
	protected void onClickStart() {
		setDown(true);
	}

	@Override
	public void setHTML(String html) {
		for (Face face : this.faces) {
			face.setHTML(html);
		}
	}

	@Override
	public void setText(String text) {
		for (Face face : this.faces) {
			face.setText(text);
		}
	}

}
